﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Ex03.GarageLogic
{
    public class GarageManagment
    {
        public enum eVehicleRepairState
        {
            DefaultValue = 0,
            InRepair,
            Repaired,
            BillPaid
        }

        private List<Vehicle> m_VehicleList;
       
        // 1
        public bool InsertVehicleToMachineShop(String i_VehicleLicenseNumber)
        {
            bool NeedToAddNewVehicle = true;
            int IndexOfVehicleInList = -1;

            IndexOfVehicleInList = FindVehicleInTheGarage(i_VehicleLicenseNumber);
            if (IndexOfVehicleInList >= 0)
            {
                ChangeVehicleState(i_VehicleLicenseNumber, eVehicleRepairState.InRepair);
                NeedToAddNewVehicle = false;
            }

            return NeedToAddNewVehicle;
        }

        public void AddNewVehicleToGarage(String i_VehicleLicenseNumber, VehicleTypes.eVehicleType i_VehicleType)
        {
            Vehicle NewVehicle = null;

            NewVehicle = VehicleTypes.CreateNewVehicle(i_VehicleType);
            NewVehicle.VehicleLicenseNumber = i_VehicleLicenseNumber;
            m_VehicleList.Add(NewVehicle);
        }

        public List<String> UpdateVehicleData(String i_LicenseNumber)
        {
            List<String> ReturnValue = null;
            int IndexOfVehicleInList = FindVehicleInTheGarage(i_LicenseNumber);
            if (IndexOfVehicleInList >= 0)
            {
             ReturnValue = m_VehicleList[IndexOfVehicleInList].CollectQustionsListToAskUser();
            }

            return ReturnValue;
        }

        public void senddate(List<String> i_Answers, String i_LicenseNumber)
        {
            int IndexOfVehicleInList = FindVehicleInTheGarage(i_LicenseNumber);
            if (IndexOfVehicleInList >= 0)
            {
                m_VehicleList[IndexOfVehicleInList].GetStringsFromUserAndUpdateVehicleData(i_Answers);
            }
        }

        //2
        public List<String> GetListOfVehiclesInGarageLicenseNumbers(
                            bool IntersectByVehicleState,
                            eVehicleRepairState DesiredStateToIntersectWith)
        {
            List<String> ListOfVehiclesLicenseToReturn = new List<String>();

            foreach (Vehicle vehicle in m_VehicleList)
            {
                if (!IntersectByVehicleState || vehicle.VehicleState == DesiredStateToIntersectWith)
                {
                    ListOfVehiclesLicenseToReturn.Add(vehicle.VehicleLicenseNumber);
                }
            }

            return ListOfVehiclesLicenseToReturn;
        }

        //3
        public void ChangeVehicleState(String i_VehicleToUpdateLicenseNumber, eVehicleRepairState NewRepairState)
        {
            int IndexOfVehicleInList = FindVehicleInTheGarage(i_VehicleToUpdateLicenseNumber);
            if (IndexOfVehicleInList >= 0)
            {
                m_VehicleList[IndexOfVehicleInList].VehicleState = NewRepairState;
            }
        }

        //4
        public void InflateAllVehicleWheelsToMaximumAirPressure(String i_VehicleLicenseNumber)
        {
            int IndexOfVehicleInList = FindVehicleInTheGarage(i_VehicleLicenseNumber);
            if (IndexOfVehicleInList >= 0)
            {
                m_VehicleList[IndexOfVehicleInList].InflateAllVehicleWheelsToMaximumAirPressure();
            }
        }

        //5
        public void RefuelInternalCombustionVehicle(String i_VehicleLicenseNumber,
                                              EnergyType.eEnergyType i_RefuelingFuelType, float i_FuelAmountToAddInLitres)
        {
            int IndexOfVehicleInList = FindVehicleInTheGarage(i_VehicleLicenseNumber);
            if (IndexOfVehicleInList >= 0)
            {
                m_VehicleList[IndexOfVehicleInList].RefualVehicle(i_RefuelingFuelType, i_FuelAmountToAddInLitres);
            }
        }

        //6
        public void RechargeElectricVehicle(String i_VehicleLicenseNumber, float i_RechargingTimeInMinutes)
        {
            int IndexOfVehicleInList = FindVehicleInTheGarage(i_VehicleLicenseNumber);
            if (IndexOfVehicleInList >= 0)
            {
                m_VehicleList[IndexOfVehicleInList].RechargeVehicle(i_RechargingTimeInMinutes);
            }
        }

        //7
        public List<String> GetAllDataAboutAVehicle(String i_VehicleLicenseNumber)
        {
            List<String> ReturnValue = null;

            int IndexOfVehicleInList = FindVehicleInTheGarage(i_VehicleLicenseNumber);
            if (IndexOfVehicleInList >= 0)
            {
                ReturnValue = m_VehicleList[IndexOfVehicleInList].GetAllInformation();
            }
            return ReturnValue;
        }

        public GarageManagment()
        {
            m_VehicleList = new List<Vehicle>();
        }

        public String[] GetVehicleType()
        {
            return VehicleTypes.GetVehicleTypeHandleByTheGarage(); ;
        }

        public String[] GetVehicleRepairState()
        {
            return Enum.GetNames(typeof(eVehicleRepairState));
        }

        public bool isVehicleInTheGarage(String i_LicenseNumber)
        {
            bool ReturnValue = false;

            if (m_VehicleList.IndexOf(new Vehicle(i_LicenseNumber)) >= 0)
            {
                ReturnValue = true;
            }

            return ReturnValue;
        }

        public int FindVehicleInTheGarage(String i_LicenseNumber)
        {
            return m_VehicleList.IndexOf(new Vehicle(i_LicenseNumber));
        }
    }
}
